package com.zzyl.nursing.controller.member;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.PropertyStatusInfo;
import com.zzyl.nursing.dto.DeviceDataListDto;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.QueryDevicePropertyStatusDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.service.IFamilyMemberService;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 用户端登录
     */
    @PostMapping("/login")
    @ApiOperation(value = "用户端登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto)
    {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);

    }
    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation(value = "按天统计查询指标数据")
    public R<List<DeviceDataListVo>> queryDeviceDataListByDay(@RequestBody DeviceDataListDto deviceDataListDto)
    {
        List<DeviceDataListVo> list = familyMemberService.queryDeviceDataListByDay(deviceDataListDto);
        return R.ok(list);
    }

    /**
     * 1.6 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation(value = "1.6 按周统计查询指标数据")
    public R<List<DeviceDataListVo>> queryDeviceDataListByWeek(@RequestBody DeviceDataListDto deviceDataListDto)
    {
        List<DeviceDataListVo> list = familyMemberService.queryDeviceDataListByWeek(deviceDataListDto);
        return R.ok(list);
    }
    /**
     * 1.4 查询健康数据
     */
    @PostMapping("/queryServiceProperties")
    @ApiOperation(value = "1.4 查询健康数据")
    public R<QueryDevicePropertyStatusVo> QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusDto queryDevicePropertyStatusDto)
    {
        QueryDevicePropertyStatusVo queryDevicePropertyStatusVo = familyMemberService.QueryDevicePropertyStatus(queryDevicePropertyStatusDto);
        return R.ok(queryDevicePropertyStatusVo);
    }
    /**
     * 绑定老人
     */
    @PostMapping("/add")
    @ApiOperation(value = "绑定老人")
    public AjaxResult add(@RequestBody MemberElderDto memberElderDto)
    {
        int i = familyMemberElderService.add(memberElderDto);
        return success(i);
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation(value = "我的家人列表")
    public R<List<FamilyMemberElderVo>> my() {
        List<FamilyMemberElderVo> memberElders = familyMemberElderService.my();
        return R.ok(memberElders);
    }

    /**
     * 查看家人列表（分页查询）
     */
    @GetMapping("/list-by-page")
    @ApiOperation(value = "查看家人列表（分页查询）")
    public R<List<MemberElderVo>> listByPage()
    {
        startPage();
        Long userId = UserThreadLocal.getUserId();
        List<MemberElderVo> memberElderVos = familyMemberElderService.listByPage(userId);
        return R.ok(memberElderVos);
    }

    /**
     * 解绑家人
     */
    @DeleteMapping("/deleteById")
    @ApiOperation(value = "解绑家人")
    public AjaxResult deleteById(@RequestParam Long id) {
        return toAjax(familyMemberElderService.deleteById(id));
    }

}
